import syscall

fn main():void! {
    string s = 'hello world!'
    var raw_str = s.ref()
    int result = syscall.call6(syscall.SYS_WRITE, syscall.STDOUT as anyptr, raw_str, s.len() as anyptr, 0, 0, 0)

    // read
    var fd = syscall.open('./asserts/stat.txt', syscall.O_RDONLY, 0666)

    var buf = vec_new<u8>(0, 100) // 预先申请好了空间, 便于 syscall 中将相应的值回写
    print('buf len: ', buf.len(), ', buf cap: ', buf.cap(), '\n')

    result = syscall.call6(syscall.SYS_READ, fd as anyptr, buf.ref(), buf.len() as anyptr, 0, 0, 0)

    print('read result: ', result, '\n')
    buf = buf.slice(0, result)
    print('buf: ', buf as string, '!!!', '\n')


    // clock_gettime
    var t = syscall.gettime()
    println('sec:', t.sec > 1691651852, 'nsec:', t.nsec > 0)

    // env
    syscall.set_env('NICE', 'hello man')
    var env = syscall.get_env('NICE')
    println('env:', env)
}